home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EGAVGA.SWG / 0161_Bouncing VGA Trails.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  3KB  |  101 lines

  1. uses
  2.   {vgaSCRN,}crt;
  3.  
  4. const
  5.   Balls = 900;  {if program too fast increase: if too slow decrease}
  6.  
  7. type
  8.   movement= record
  9.     x,   y : integer;  { position }
  10.     dx,  dy : integer;  { velocity }
  11.     ddx, ddy : integer;  { acceleration }
  12.     color    : integer;
  13.     MaxYValue: integer;
  14.   END;
  15.  
  16. VAR
  17.   ch : char;           {for readkey}
  18.   I  : integer;
  19.   Ball : array[1..BAlls] of movement;
  20.  
  21. procedure PutDot(x,y,color:integer);
  22. begin
  23.   Mem[$a000{VGA_Segment}:(y*320)+x] := color;
  24. end;
  25.  
  26. Procedure VideoMode ( Mode : Byte );
  27. Begin { VideoMode }
  28.   Asm
  29.     Mov  AH,00
  30.     Mov  AL,Mode
  31.     Int  10h
  32.   End;
  33. End;  { VideoMode }
  34.  
  35. BEGIN {MAIN}
  36.   videoMODE($13); {320x200x256c}
  37.   {init all balls}
  38.   FOR I:=1 to BAlls do
  39.   BEGIN
  40.     With ball[i] do
  41.     BEGIN
  42.       ddx := 0; { constant horizontal acceleration }  {gravity < or >}
  43.       ddy := 0; { constant vertical acceleration } {gravity ^ or v }
  44.  
  45.       { in this case there is NO gravity pull from ANY direction: weightless}
  46.       dx := Random(2)-1;             { initial velocity < or >}
  47.       dy := -1;                      { initial velocity ^ or v}
  48.  
  49.       x := i mod 305+random(15)+1; { initial coordinates, as }
  50.       y := I mod 190+random(10)+1; {   you specified }
  51.  
  52.       { 320 * 200 positioning : take I and remainder when divided by 'balls'
  53.         to produce a sequential increment that does not over flow 320 or 200;
  54.         plus a random to give the fuzzy line effect}
  55.  
  56.       color:=Random( I div ((I div 254)+1)) + 1;  {Each Balls color}
  57.       { This formula will take a loop from 1 to [any number] and make it so it
  58.         will increment from 1 to 255 [valid color assignments]}
  59.       MaxYValue:=Y+1;  {future use only}
  60.     END; {with}
  61.   END; {for do loop}
  62.  
  63.  
  64.   WHILE not(keypressed) do
  65.   begin
  66.     FOR i:=1 to Balls do
  67.     BEGIN
  68.       With ball[i] do
  69.       BEGIN
  70.         putdot(x, y, 0);    { blank out the pixel drawn on the last
  71.         iteration } dx := dx + ddx;     { updating velocity }
  72.         dy := dy + ddy;
  73.         x  :=  x +  dx;     { updating position }
  74.         y  :=  y +  dy;
  75.         IF x< 1 then
  76.         begin      {hits left of screen}
  77.           X:=1;
  78.           dx:=dx*-1;           {moves it to the right}
  79.         End;
  80.  
  81.         IF x > 319 then
  82.         begin   {hits right of screen}
  83.           x :=319;
  84.           dx:=-dx;             {moves it to the left}
  85.         END;
  86.  
  87.         IF y > 190 then
  88.         begin   { BOUNCE! }
  89.           y := 190;
  90.           dy := -dy;            {not used: all object float upward not down}
  91.         End;
  92.         putdot(x, y, color);  { draw the pixel at the new position }
  93.       END; {WITH}
  94.     END; {for do loop}
  95.   End; {KEYPRESS}
  96.  
  97.   videoMODe($3);          {back to text mode}
  98. end. {PROGRAM}
  99.  
  100.  
  101.